//
//  MessageModleHelper.m
//  AirQuality
//
//  Created by Po on 15/9/16.
//  Copyright © 2015年 Po. All rights reserved.
//

#import "MessageModleHelper.h"

@implementation MessageModleHelper

- (instancetype)init
{
    self = [super init];
    if (self) {
    }
    return self;
}

- (void)doNetRequest
{
    NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile:GetFilePath(@"MessageData.plist")];
    _messageTime = dic[@"time"];
    if ([_messageTime isEqualToString:@""]) {
        _messageTime = [NSString stringWithFormat:@"%@ 00:00:00", [RJTools getTimeWithFormat:@"yyyy-MM-dd"]];
    }
    
    [RJNetWork myNetRequestWithAddress:@"http://newair.scemc.cn:5100/dataShare/getSystemMessages" data:@{@"timepoint":_messageTime} completeBlock:^(id responseObject) {
        _model = [NSArray arrayWithArray:responseObject[@"data"]];
        if (responseObject[@"result"] && [responseObject[@"data"] count] > 0) {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"setMessageDataStatus" object:@{@"haveData":@YES}];
            [[NSNotificationCenter defaultCenter] postNotificationName:@"getDataNotification" object:nil userInfo:@{@"result":@YES}];
        } else {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"getDataNotification" object:nil userInfo:@{@"result":@NO}];
        }
    } failBlack:^(id response) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"getDataNotification" object:nil userInfo:@{@"result":@NO}];
    }];
}

@end
